package com.quanjiaolian.userinfo.servlet;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.quanjiaolian.tools.ResponseToJson;
import com.quanjiaolian.userinfo.service.MsgCenterService;
import com.quanjiaolian.userinfo.serviceimpl.MsgCenterServiceImpl;

@SuppressWarnings("serial")
public class MsgCenterAction extends HttpServlet {
	
	/**
	 * 声明Log4j变量
	 */
	public static ResourceBundle resourceBundle = null;
	static Logger logger = Logger.getLogger(MsgCenterAction.class.getName());
	MsgCenterService ms = new MsgCenterServiceImpl(); 
	
	/**
	 *获得所有系统信息 
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		Map<String,Object> resultMap = new HashMap<String,Object>();
		List<Object> list = ms.queryAdminMsg();
		resultMap.put("result",list);
		ResponseToJson.responseOutWithJson(response,resultMap);
		
	}

	/**
	 * 消息中心用户互动信息查询
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		Map<String,Object> resultMap = new HashMap<String,Object>();
		String user_type = request.getParameter("user_type");
		String replay_id = request.getParameter("replay_id");
		try{
			List<Object> list = ms.queryUserMsgById(Integer.parseInt(replay_id),Integer.parseInt(user_type));
			if(list.size()>0){
				resultMap.put("result",list);
			}else{
				resultMap.put("result","no result");
			}
		}catch (Exception e) {
			resultMap.put("result","Error");
			e.printStackTrace();
		}
		ResponseToJson.responseOutWithJson(response,resultMap);
	}

}
